<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Generic controller for entity class, CI AR.
 * @author hmQuan
 *
 */
class MY_Controller extends CI_Controller {

	//contructor class
	function __construct() {

		parent::__construct();
	}

	/**
	 * General function here
	 */
	
	/**
	 * 
	 */
	public function check_post_value($post = null){
		// check post is null
		if($post){

			// check value with key data
			if(isset($post[DATA])){
				$data = json_decode($post[DATA], true);
				//check token in server
				if(!empty($data[GCM_REGID]) && isset($data[GCM_REGID])){
					return $data;
					// $gcm_regid = $this->gcmmodel->countRegIdAlreadyExist($data[GCM_REGID]);
					// if($gcm_regid == 0 ){
					// 	$this->print_result(array('check_post_value'=> 'Device Undifined'), 0);
					// 	exit();
					// }else{
					// 	return $data;	
					// }
				}else{
					$this->print_result(array('check_post_value'=>'missing token.'), 0);
				exit();
				}
			}else{

				$this->print_result(array('check_post_value'=>'missing key : data.'), 0);
				exit();
			}
		}else{

			$this->print_result('post null.', 0);
			exit();
		}
	}

	/**
	 * return result to client
	 */
	public function print_result($data = array(), $success = 0){
		$result = array( SUCCESS => $success, DATA => $data);

		echo json_encode($result);
	}	
}